package com.zeng.aop.restmodel;

import com.zeng.bean.restmodel.RestModelInfo;
import com.zeng.bean.restmodel.RestQueryParam;
import com.zeng.service.restmodel.RestModelService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

@Aspect
@Slf4j
public class RestModelServiceAop {

    @Around("execution(* com.zeng.service.restmodel.RestModelService.*(com.zeng.bean.restmodel.RestQueryParam))")
    public Object check(ProceedingJoinPoint joinPoint) throws Throwable {
        RestQueryParam arg = (RestQueryParam) joinPoint.getArgs()[0];
        RestModelService target = (RestModelService) joinPoint.getTarget();
        RestModelInfo modelInfo = target.getModelInfo();
        if(!modelInfo.getTableName().equalsIgnoreCase(arg.getTableName())){
            throw new IllegalArgumentException("非法的表名"+ arg.getTableName());
        }

        return joinPoint.proceed();
    }
}
